package com.learn;

/**
 * 给定一个字符串，你需要反转字符串中每个单词的字符顺序，同时仍保留空格和单词的初始顺序。
 */

public class num_557 {
    public static String reverseWords(String s) {
        String[] stringArr = s.split(" ");
//        int begin=0;
        String res=new String();
        for (String s1 : stringArr) {
            char[] chars = s1.toCharArray();
            int left = 0;
            int right=chars.length-1;
            while (left < right) {
                char tmp=chars[left];
                chars[left]=chars[right];
                chars[right]=tmp;
                left++;
                right--;
            }
            res=res+String.valueOf(chars)+" ";
//            stringArr[begin]=String.valueOf(chars);
//            begin++;
        }


        return res.substring(0,res.length()-1);
    }

    public static void main(String[] args) {
        String s = "Let's take LeetCode contest";
        System.out.println(reverseWords(s));

    }
}
